<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="序号"  min-width="20%">
        <template slot-scope="scope">
          {{ scope.$index+1 }}
        </template>
      </el-table-column>

      <el-table-column label="用户名" align="center"  min-width="30%">
        <template slot-scope="scope">
          <span>{{ scope.row.deviceid }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center"  min-width="20%">
        <template slot-scope="scope">
          {{ scope.row.online?"在线":"离线" }}
        </template>
      </el-table-column>
      <el-table-column label="操作"  align="center" min-width="30%">
        <template slot-scope="scope">
          <el-button type="primary" @click="channels(scope.row.deviceid)" class="el-icon-arrow-right" size="mini">查看通道</el-button>
          <el-button @click="catalog(scope.row.deviceid)" class="el-icon-refresh" size="mini">更新通道</el-button>
          <el-button type="danger" @click="del(scope.row.deviceid)" class="el-icon-delete" size="mini">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>

</template>

<script>
import { list,catalog,delcamera } from '@/api/camera'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true
    }
  },

  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      list().then(response => {
        this.list = response.data.items
        this.listLoading = false
      })
    },
    channels(id) {
      this.$router.push({ path: '/camera/channel', query: { account: id }})
    },
    // 刷新目录
    catalog(id) {
      this.listLoading = true;
      catalog({ account: id }).then(response => {
        console.log('catalog response', response)
        this.listLoading=false;
      })
    },

    del(id) {
      this.$confirm('确认删除此通道？').then(_ => {
        this.listLoading=true;
        delcamera({ account: id}).then(response=>{
          this.listLoading=false;
          this.fetchData()
        })
      }).catch(_ => {

      })
    },
    handleClose(done) {
      done()
    }
  }
}
</script>

<style>
  .video-js .vjs-icon-placeholder {
      width: 100%;
      height: 100%;
      display: block;
  }
</style>
